//
//  UIView+LGIndicator.m
//  UniverseProject
//
//  Created by king on 2018/12/10.
//  Copyright © 2018年 Cloud2209. All rights reserved.
//


static NSString *const unitKey = @"loadingView";

#import "LGIndicatorView.h"
#import <objc/runtime.h>
#import "UIView+LGIndicator.h"



@implementation UIView (LGIndicator)

- (void)setLoadingView:(LGIndicatorView *)loadingView{
    objc_setAssociatedObject(self, &unitKey, loadingView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (UIView *)loadingView{
    return objc_getAssociatedObject(self, &unitKey);
}

- (void)showIndicator{
    if (!self.loadingView) {
        LGIndicatorView *loadingView = [[LGIndicatorView alloc] initWithFrame:self.bounds];
        [self addSubview:loadingView];
        self.loadingView = loadingView;
    }else{
        [self.loadingView.activityIndicator startAnimating];
    }
}

- (void)hideIndicator{
    [self.loadingView.activityIndicator hideIndicator];
    [self.loadingView removeFromSuperview];
}


@end
